package com.txsj.scan.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.txsj.scan.R;
import com.txsj.scan.bean.AllocationDetailsBean;
import com.txsj.scan.utils.AppDateMgr;

import java.util.ArrayList;
import java.util.List;



/**
 * Created by 冯瑞雨 on 2018/12/11.
 */
public class AllocationDetailsRcAdapeter extends RecyclerView.Adapter<AllocationDetailsRcAdapeter.SelectEnterpriseItemRvView> {

    private Context context;
    private  List<AllocationDetailsBean.DetailsBean> list = new ArrayList<>();

    public AllocationDetailsRcAdapeter(Context context) {
        this.context = context;
    }

    public List<AllocationDetailsBean.DetailsBean> getList() {
        return list;
    }

    public void setList(List<AllocationDetailsBean.DetailsBean> list) {
        this.list = list;
    }

    @Override
    public SelectEnterpriseItemRvView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.allocation_detail_rv_ad, parent, false);
        return new SelectEnterpriseItemRvView(view);
    }

    @Override
    public void onBindViewHolder(final SelectEnterpriseItemRvView holder, final int position) {
        if (!TextUtils.isEmpty(list.get(position).getExpiry_time())) {
            if (list.get(position).getExpiry_time().indexOf("9999-12-31") != -1) {
                holder.tv_date.setText("长期有效");
                holder.tv_date.setTextColor(Color.RED);
            } else {
                holder.tv_date.setText(AppDateMgr.getDateFormat(list.get(position).getExpiry_time()));
            }
        }

        holder.tv_batch.setText(list.get(position).getBatch_id()+"");
        holder.tv_count.setText(list.get(position).getGoods_count()+"");

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectEnterpriseItemRvView extends RecyclerView.ViewHolder {

        TextView tv_date;
        TextView tv_batch;
        TextView tv_count;

        public SelectEnterpriseItemRvView(View itemView) {
            super(itemView);
            tv_date  = (TextView) itemView.findViewById(R.id.tv_date);
            tv_batch  = (TextView) itemView.findViewById(R.id.tv_batch);
            tv_count  = (TextView) itemView.findViewById(R.id.tv_count);
        }
    }

    public OnItemChangeListener listener;

    public void setListener(OnItemChangeListener listener) {
        this.listener = listener;
    }

    public interface OnItemChangeListener {
        void onChange(int position, int count);
    }

}